/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PedidoDialog.java
 *
 * Created on Nov 9, 2010, 9:44:54 PM
 */
package br.com.tbp.gui;

import br.com.tbp.controle.ControleAjudaCusto;
import br.com.tbp.controle.ControleEmpresa;
import br.com.tbp.controle.ControlePedido;
import br.com.tbp.controle.ControleProduto;
import br.com.tbp.exception.PersistenciaException;
import br.com.tbp.gui.table.ItensDePedidoTableModel;
import br.com.tbp.gui.table.SituacoesExternasTableModel;
import br.com.tbp.gui.table.JTableUtils;
import br.com.tbp.gui.table.SituacoesInternasTableModel;
import br.com.tbp.model.domain.Boc;
import br.com.tbp.model.domain.Consultor;
import br.com.tbp.model.domain.Empresa;
import br.com.tbp.model.domain.SituacaoExterna;
import br.com.tbp.model.domain.ItemDePedido;
import br.com.tbp.model.domain.Pedido;
import br.com.tbp.model.domain.Produto;
import br.com.tbp.model.domain.StatusPedido;
import br.com.tbp.model.domain.SituacaoInterna;
import br.com.tbp.model.domain.Supervisor;
import br.com.tbp.model.domain.constant.CondicaoDaLinha;
import br.com.tbp.model.domain.constant.Departamento;
import br.com.tbp.utils.Atributo;
import br.com.tbp.utils.DateUtils;
import br.com.tbp.utils.ImageUtils;
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.sql.Timestamp;
import java.util.Date;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.KeyStroke;

/**
 *
 * @author Diego Freire
 */
public class PedidoDialog extends javax.swing.JDialog {

    private ItensDePedidoTableModel model_itens_pedido;
    private SituacoesExternasTableModel model_situacoes_externas;
    private SituacoesInternasTableModel model_situacoes_internas;
    private Pedido pedido;
    private boolean novoPedido;
    private boolean add_info = true;
    private Produto produto_add;
    private MenuPrincipal menu;
    private SituacaoExterna situacaoExterna;
    private SituacaoInterna situacaoInterna;
    private JButton buscaConsultorButton, buscaEmpresaButton, buscaBocButton, updateEmpresaButton;

    public PedidoDialog(java.awt.Frame parent, String title, boolean modal) {
        super(parent, title, modal);
        initComponents();
        if (parent instanceof MenuPrincipal) {
            this.menu = (MenuPrincipal) parent;
        }
        posInit();
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        group1 = new javax.swing.ButtonGroup();
        tabbed1 = new javax.swing.JTabbedPane();
        basicoPanel = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel43 = new javax.swing.JPanel();
        jPanel14 = new javax.swing.JPanel();
        infoLabel = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        consultorTextField = new javax.swing.JTextField();
        empresaTextField = new javax.swing.JTextField();
        idConsultorTexField = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        idEmpresaTexField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        idSupervisorTexField = new javax.swing.JTextField();
        supervisorTextField = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        idBocTexField = new javax.swing.JTextField();
        bocTextField = new javax.swing.JTextField();
        infoPanel = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        qtdeTextField = new javax.swing.JTextField();
        inserirButton = new javax.swing.JButton();
        produtosLabel = new javax.swing.JLabel();
        itensLabel = new javax.swing.JLabel();
        jPanel19 = new javax.swing.JPanel();
        produtoButton = new javax.swing.JButton();
        produtoComboBox = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        condicaoComboBox = new javax.swing.JComboBox();
        portInCheckBox = new javax.swing.JCheckBox();
        jLabel8 = new javax.swing.JLabel();
        qtdePortInTextField = new javax.swing.JTextField();
        jPanel8 = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        scrollpane = new javax.swing.JScrollPane();
        itensDePedidoTable = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jPanel15 = new javax.swing.JPanel();
        atualizarButon = new javax.swing.JButton();
        removerButton = new javax.swing.JButton();
        limparButton = new javax.swing.JButton();
        jPanel22 = new javax.swing.JPanel();
        finalizadoLabel = new javax.swing.JLabel();
        historicoPanel = new javax.swing.JPanel();
        tabbed2 = new javax.swing.JTabbedPane();
        internoPanel = new javax.swing.JPanel();
        jPanel20 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        departamentoComboBox = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        obsInternaTextArea = new javax.swing.JTextArea();
        trocarDepartamentoButton = new javax.swing.JButton();
        atualizarDepartamentoButton = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        dataEntradaInternaTextField = new org.jdesktop.swingx.JXDatePicker();
        cancelarDepartamentoButton = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        tempoLabel = new javax.swing.JLabel();
        jPanel21 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        situacoesInternasTable = new javax.swing.JTable();
        jPanel24 = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        excluirSituacaoInternaButton = new javax.swing.JButton();
        externoPanel = new javax.swing.JPanel();
        jPanel11 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        situacaoCombo = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        obsExternaTextArea = new javax.swing.JTextArea();
        inserirSituacaoButton = new javax.swing.JButton();
        atualizarHistoricoButton = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        dataEntradaExternaTextField = new org.jdesktop.swingx.JXDatePicker();
        cancelarHistoricoButton = new javax.swing.JButton();
        jPanel16 = new javax.swing.JPanel();
        jPanel17 = new javax.swing.JPanel();
        jSeparator1 = new javax.swing.JSeparator();
        jPanel18 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        situacoesExternasTable = new javax.swing.JTable();
        jPanel23 = new javax.swing.JPanel();
        jLabel17 = new javax.swing.JLabel();
        excluirSituacaoExternaButton = new javax.swing.JButton();
        bocPanel = new javax.swing.JPanel();
        jLabel19 = new javax.swing.JLabel();
        planoField = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        P2BField = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        radarField = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        situacaoField = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        bocField = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        dataInputField = new org.jdesktop.swingx.JXDatePicker();
        jPanel10 = new javax.swing.JPanel();
        jPanel12 = new javax.swing.JPanel();
        salvarButton = new javax.swing.JButton();
        fecharButton = new javax.swing.JButton();
        jPanel13 = new javax.swing.JPanel();
        novoPedidoButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        msgLabel = new javax.swing.JLabel();
        empresaLabel = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        dataEmissaoTextField = new org.jdesktop.swingx.JXDatePicker();
        jPanel25 = new javax.swing.JPanel();
        jLabel25 = new javax.swing.JLabel();
        primeiraVendaRadio = new javax.swing.JRadioButton();
        aditivoRadio = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        tabbed1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                tabbed1StateChanged(evt);
            }
        });

        basicoPanel.setLayout(new java.awt.BorderLayout());

        jPanel2.setLayout(new java.awt.BorderLayout());

        jPanel43.setLayout(new java.awt.BorderLayout());

        jPanel14.setPreferredSize(new java.awt.Dimension(910, 145));

        infoLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/plus_16.png"))); // NOI18N
        infoLabel.setText("Informações");
        infoLabel.setToolTipText("Ver mais informações do cliente");
        infoLabel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        infoLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                infoLabelMouseClicked(evt);
            }
        });

        jLabel2.setText("Consultor:");

        consultorTextField.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        consultorTextField.setFocusable(false);
        consultorTextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                consultorTextFieldMouseClicked(evt);
            }
        });

        empresaTextField.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        empresaTextField.setFocusable(false);
        empresaTextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                empresaTextFieldMouseClicked(evt);
            }
        });

        idConsultorTexField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        idConsultorTexField.setFocusable(false);

        jLabel9.setText("Empresa:");

        idEmpresaTexField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        idEmpresaTexField.setFocusable(false);

        jLabel3.setText("Supervisor:");

        idSupervisorTexField.setEditable(false);
        idSupervisorTexField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        idSupervisorTexField.setFocusable(false);

        supervisorTextField.setEditable(false);
        supervisorTextField.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        supervisorTextField.setFocusable(false);

        jLabel10.setText("BOC:");

        idBocTexField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        idBocTexField.setFocusable(false);

        bocTextField.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        bocTextField.setFocusable(false);
        bocTextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bocTextFieldMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel14Layout = new javax.swing.GroupLayout(jPanel14);
        jPanel14.setLayout(jPanel14Layout);
        jPanel14Layout.setHorizontalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(infoLabel)
                    .addGroup(jPanel14Layout.createSequentialGroup()
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel9)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel10))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(idBocTexField)
                            .addComponent(idSupervisorTexField)
                            .addComponent(idEmpresaTexField)
                            .addComponent(idConsultorTexField, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(bocTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 771, Short.MAX_VALUE)
                            .addComponent(supervisorTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 771, Short.MAX_VALUE)
                            .addComponent(empresaTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 771, Short.MAX_VALUE)
                            .addComponent(consultorTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 771, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel14Layout.setVerticalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(idConsultorTexField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(consultorTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(4, 4, 4)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(idEmpresaTexField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(empresaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(idSupervisorTexField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(supervisorTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(idBocTexField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bocTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(infoLabel)
                .addContainerGap())
        );

        jPanel43.add(jPanel14, java.awt.BorderLayout.PAGE_START);

        infoPanel.setLayout(new java.awt.BorderLayout());
        jPanel43.add(infoPanel, java.awt.BorderLayout.PAGE_END);

        jPanel2.add(jPanel43, java.awt.BorderLayout.PAGE_START);

        jPanel6.setLayout(new java.awt.BorderLayout());

        jPanel7.setBackground(new java.awt.Color(195, 223, 251));
        jPanel7.setPreferredSize(new java.awt.Dimension(924, 98));

        jLabel13.setText("Produto");

        jLabel16.setText("Qtde.");

        qtdeTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        qtdeTextField.setText("0");
        qtdeTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                qtdeTextFieldFocusGained(evt);
            }
        });

        inserirButton.setBackground(new java.awt.Color(255, 255, 255));
        inserirButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/down.png"))); // NOI18N
        inserirButton.setText("INSERIR");
        inserirButton.setToolTipText("Lança produto no pedido");
        inserirButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inserirButtonActionPerformed(evt);
            }
        });

        produtosLabel.setText("Qtde de produtos: 0");

        itensLabel.setText("Qtde de itens: 0");

        jPanel19.setLayout(new java.awt.BorderLayout());

        produtoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/search16.png"))); // NOI18N
        produtoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                produtoButtonActionPerformed(evt);
            }
        });
        jPanel19.add(produtoButton, java.awt.BorderLayout.LINE_START);

        produtoComboBox.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                produtoComboBoxFocusLost(evt);
            }
        });
        jPanel19.add(produtoComboBox, java.awt.BorderLayout.CENTER);

        jLabel7.setText("Condição");

        condicaoComboBox.setModel(new DefaultComboBoxModel(CondicaoDaLinha.values()));

        portInCheckBox.setText("Port In");
        portInCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                portInCheckBoxActionPerformed(evt);
            }
        });

        jLabel8.setText("Qtde. Port In");
        jLabel8.setEnabled(false);

        qtdePortInTextField.setEditable(false);
        qtdePortInTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        qtdePortInTextField.setText("0");
        qtdePortInTextField.setFocusable(false);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(produtosLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(itensLabel))
                    .addComponent(jLabel13)
                    .addComponent(jPanel19, javax.swing.GroupLayout.PREFERRED_SIZE, 434, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(condicaoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(inserirButton, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel7Layout.createSequentialGroup()
                                .addComponent(qtdeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(portInCheckBox))
                            .addComponent(jLabel16))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(qtdePortInTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(17, 17, 17))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel7Layout.createSequentialGroup()
                                .addComponent(jLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanel19, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(jPanel7Layout.createSequentialGroup()
                                    .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel8)
                                        .addComponent(jLabel16))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(qtdePortInTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel7Layout.createSequentialGroup()
                                    .addComponent(jLabel7)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(condicaoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel7Layout.createSequentialGroup()
                                    .addGap(18, 18, 18)
                                    .addComponent(portInCheckBox))
                                .addComponent(qtdeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(6, 6, 6)
                        .addComponent(inserirButton))
                    .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(produtosLabel)
                        .addComponent(itensLabel)))
                .addContainerGap())
        );

        jPanel6.add(jPanel7, java.awt.BorderLayout.PAGE_START);

        jPanel8.setLayout(new java.awt.BorderLayout());

        jPanel9.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 3, 0, 1));
        jPanel9.setLayout(new java.awt.BorderLayout());

        scrollpane.setPreferredSize(new java.awt.Dimension(453, 200));

        itensDePedidoTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        itensDePedidoTable.setSelectionBackground(new java.awt.Color(235, 169, 169));
        itensDePedidoTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        itensDePedidoTable.setShowHorizontalLines(false);
        scrollpane.setViewportView(itensDePedidoTable);

        jPanel9.add(scrollpane, java.awt.BorderLayout.CENTER);

        jPanel3.setLayout(new java.awt.BorderLayout());

        atualizarButon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/lapis_16.png"))); // NOI18N
        atualizarButon.setText("Alterar Quantidade");
        atualizarButon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atualizarButonActionPerformed(evt);
            }
        });
        jPanel15.add(atualizarButon);

        removerButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/trash.png"))); // NOI18N
        removerButton.setText("Remover Item");
        removerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removerButtonActionPerformed(evt);
            }
        });
        jPanel15.add(removerButton);

        limparButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/blank.png"))); // NOI18N
        limparButton.setText("Limpar Itens");
        limparButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                limparButtonActionPerformed(evt);
            }
        });
        jPanel15.add(limparButton);

        jPanel3.add(jPanel15, java.awt.BorderLayout.LINE_START);

        jPanel22.setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 1, 0, 1));
        jPanel22.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        finalizadoLabel.setForeground(new java.awt.Color(255, 51, 51));
        jPanel22.add(finalizadoLabel);

        jPanel3.add(jPanel22, java.awt.BorderLayout.LINE_END);

        jPanel9.add(jPanel3, java.awt.BorderLayout.PAGE_START);

        jPanel8.add(jPanel9, java.awt.BorderLayout.CENTER);

        jPanel6.add(jPanel8, java.awt.BorderLayout.CENTER);

        jPanel2.add(jPanel6, java.awt.BorderLayout.CENTER);

        basicoPanel.add(jPanel2, java.awt.BorderLayout.CENTER);

        tabbed1.addTab("Info. Básicas", basicoPanel);

        historicoPanel.setLayout(new java.awt.BorderLayout());

        tabbed2.setTabPlacement(javax.swing.JTabbedPane.LEFT);
        tabbed2.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                tabbed2StateChanged(evt);
            }
        });

        internoPanel.setLayout(new java.awt.BorderLayout());

        jPanel20.setBackground(new java.awt.Color(195, 223, 251));
        jPanel20.setPreferredSize(new java.awt.Dimension(920, 212));

        jLabel11.setText("Escolha o departamento atual");

        departamentoComboBox.setModel(new DefaultComboBoxModel(Departamento.values()));

        jLabel12.setText("Observações");

        obsInternaTextArea.setColumns(20);
        obsInternaTextArea.setLineWrap(true);
        obsInternaTextArea.setRows(5);
        obsInternaTextArea.setWrapStyleWord(true);
        jScrollPane3.setViewportView(obsInternaTextArea);

        trocarDepartamentoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/down.png"))); // NOI18N
        trocarDepartamentoButton.setText("Trocar Departamento");
        trocarDepartamentoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                trocarDepartamentoButtonActionPerformed(evt);
            }
        });

        atualizarDepartamentoButton.setText("Atualizar");
        atualizarDepartamentoButton.setEnabled(false);
        atualizarDepartamentoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atualizarDepartamentoButtonActionPerformed(evt);
            }
        });

        jLabel14.setText("Data de entrada");

        cancelarDepartamentoButton.setText("Cancelar");
        cancelarDepartamentoButton.setEnabled(false);
        cancelarDepartamentoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarDepartamentoButtonActionPerformed(evt);
            }
        });

        jLabel15.setText("Tempo decorrido do pedido:");

        tempoLabel.setText("0d");

        javax.swing.GroupLayout jPanel20Layout = new javax.swing.GroupLayout(jPanel20);
        jPanel20.setLayout(jPanel20Layout);
        jPanel20Layout.setHorizontalGroup(
            jPanel20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel20Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel20Layout.createSequentialGroup()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 902, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanel20Layout.createSequentialGroup()
                        .addGroup(jPanel20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel12)
                            .addComponent(jLabel11)
                            .addComponent(departamentoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 727, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel20Layout.createSequentialGroup()
                                .addComponent(jLabel14)
                                .addGap(77, 77, 77))
                            .addGroup(jPanel20Layout.createSequentialGroup()
                                .addComponent(dataEntradaInternaTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addContainerGap())))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel20Layout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tempoLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 369, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelarDepartamentoButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(atualizarDepartamentoButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(trocarDepartamentoButton)
                        .addContainerGap())))
        );
        jPanel20Layout.setVerticalGroup(
            jPanel20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel20Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(departamentoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dataEntradaInternaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(trocarDepartamentoButton)
                    .addComponent(atualizarDepartamentoButton)
                    .addComponent(cancelarDepartamentoButton)
                    .addComponent(jLabel15)
                    .addComponent(tempoLabel))
                .addContainerGap())
        );

        internoPanel.add(jPanel20, java.awt.BorderLayout.PAGE_START);

        jPanel21.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 3, 1, 3));
        jPanel21.setLayout(new java.awt.BorderLayout());

        jScrollPane4.setPreferredSize(new java.awt.Dimension(453, 200));

        situacoesInternasTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        situacoesInternasTable.setSelectionBackground(new java.awt.Color(235, 169, 169));
        situacoesInternasTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        situacoesInternasTable.setShowHorizontalLines(false);
        situacoesInternasTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                situacoesInternasTableMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(situacoesInternasTable);

        jPanel21.add(jScrollPane4, java.awt.BorderLayout.CENTER);

        jLabel18.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/right-azul.png"))); // NOI18N
        jLabel18.setText("Histórico de Situações Internas");

        excluirSituacaoInternaButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/trash.png"))); // NOI18N
        excluirSituacaoInternaButton.setText("Excluir");
        excluirSituacaoInternaButton.setToolTipText("Excluir situação interna");
        excluirSituacaoInternaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                excluirSituacaoInternaButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel24Layout = new javax.swing.GroupLayout(jPanel24);
        jPanel24.setLayout(jPanel24Layout);
        jPanel24Layout.setHorizontalGroup(
            jPanel24Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel24Layout.createSequentialGroup()
                .addComponent(excluirSituacaoInternaButton, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 601, Short.MAX_VALUE)
                .addComponent(jLabel18)
                .addContainerGap())
        );
        jPanel24Layout.setVerticalGroup(
            jPanel24Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel24Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(excluirSituacaoInternaButton)
                .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel21.add(jPanel24, java.awt.BorderLayout.PAGE_START);

        internoPanel.add(jPanel21, java.awt.BorderLayout.CENTER);

        tabbed2.addTab("Interno", internoPanel);

        externoPanel.setLayout(new java.awt.BorderLayout());

        jPanel11.setBackground(new java.awt.Color(111, 242, 144));
        jPanel11.setPreferredSize(new java.awt.Dimension(920, 212));

        jLabel1.setText("Escolha a situação atual");

        situacaoCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { " " }));

        jLabel5.setText("Observações");

        obsExternaTextArea.setColumns(20);
        obsExternaTextArea.setLineWrap(true);
        obsExternaTextArea.setRows(5);
        obsExternaTextArea.setWrapStyleWord(true);
        jScrollPane1.setViewportView(obsExternaTextArea);

        inserirSituacaoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/down.png"))); // NOI18N
        inserirSituacaoButton.setText("Inserir Situação");
        inserirSituacaoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inserirSituacaoButtonActionPerformed(evt);
            }
        });

        atualizarHistoricoButton.setText("Atualizar");
        atualizarHistoricoButton.setEnabled(false);
        atualizarHistoricoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atualizarHistoricoButtonActionPerformed(evt);
            }
        });

        jLabel6.setText("Data de entrada");

        cancelarHistoricoButton.setText("Cancelar");
        cancelarHistoricoButton.setEnabled(false);
        cancelarHistoricoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarHistoricoButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel11Layout.createSequentialGroup()
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 902, Short.MAX_VALUE)
                            .addContainerGap())
                        .addGroup(jPanel11Layout.createSequentialGroup()
                            .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel5)
                                .addComponent(jLabel1)
                                .addComponent(situacaoCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 727, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(jPanel11Layout.createSequentialGroup()
                                    .addComponent(jLabel6)
                                    .addGap(77, 77, 77))
                                .addGroup(jPanel11Layout.createSequentialGroup()
                                    .addComponent(dataEntradaExternaTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addContainerGap()))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel11Layout.createSequentialGroup()
                        .addComponent(cancelarHistoricoButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(atualizarHistoricoButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(inserirSituacaoButton)
                        .addContainerGap())))
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(situacaoCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dataEntradaExternaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(inserirSituacaoButton)
                    .addComponent(atualizarHistoricoButton)
                    .addComponent(cancelarHistoricoButton))
                .addContainerGap())
        );

        externoPanel.add(jPanel11, java.awt.BorderLayout.PAGE_START);

        jPanel16.setLayout(new java.awt.BorderLayout());

        jPanel17.setLayout(new java.awt.BorderLayout());
        jPanel17.add(jSeparator1, java.awt.BorderLayout.PAGE_START);

        jPanel16.add(jPanel17, java.awt.BorderLayout.PAGE_START);

        jPanel18.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 3, 1, 3));
        jPanel18.setLayout(new java.awt.BorderLayout());

        jScrollPane2.setPreferredSize(new java.awt.Dimension(453, 200));

        situacoesExternasTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        situacoesExternasTable.setSelectionBackground(new java.awt.Color(235, 169, 169));
        situacoesExternasTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        situacoesExternasTable.setShowHorizontalLines(false);
        situacoesExternasTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                situacoesExternasTableMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(situacoesExternasTable);

        jPanel18.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/right-verde.png"))); // NOI18N
        jLabel17.setText("Histórico de Situações Externas");

        excluirSituacaoExternaButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/trash.png"))); // NOI18N
        excluirSituacaoExternaButton.setText("Excluir");
        excluirSituacaoExternaButton.setToolTipText("Excluir situação externa");
        excluirSituacaoExternaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                excluirSituacaoExternaButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel23Layout = new javax.swing.GroupLayout(jPanel23);
        jPanel23.setLayout(jPanel23Layout);
        jPanel23Layout.setHorizontalGroup(
            jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel23Layout.createSequentialGroup()
                .addComponent(excluirSituacaoExternaButton, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 597, Short.MAX_VALUE)
                .addComponent(jLabel17)
                .addContainerGap())
        );
        jPanel23Layout.setVerticalGroup(
            jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel17, javax.swing.GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)
                .addComponent(excluirSituacaoExternaButton))
        );

        jPanel18.add(jPanel23, java.awt.BorderLayout.PAGE_START);

        jPanel16.add(jPanel18, java.awt.BorderLayout.CENTER);

        externoPanel.add(jPanel16, java.awt.BorderLayout.CENTER);

        tabbed2.addTab("Externo", externoPanel);

        jLabel19.setText("Plano");

        jLabel20.setText("P2B");

        jLabel21.setText("Radar");

        jLabel22.setText("Situação");

        situacaoField.setEditable(false);
        situacaoField.setFocusable(false);

        jLabel23.setText("BOC");

        bocField.setEditable(false);
        bocField.setFocusable(false);

        jLabel24.setText("Data input");

        javax.swing.GroupLayout bocPanelLayout = new javax.swing.GroupLayout(bocPanel);
        bocPanel.setLayout(bocPanelLayout);
        bocPanelLayout.setHorizontalGroup(
            bocPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(bocPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(bocPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(planoField, javax.swing.GroupLayout.DEFAULT_SIZE, 902, Short.MAX_VALUE)
                    .addComponent(jLabel19)
                    .addComponent(jLabel20)
                    .addComponent(P2BField, javax.swing.GroupLayout.DEFAULT_SIZE, 902, Short.MAX_VALUE)
                    .addComponent(jLabel21)
                    .addComponent(radarField, javax.swing.GroupLayout.DEFAULT_SIZE, 902, Short.MAX_VALUE)
                    .addComponent(situacaoField, javax.swing.GroupLayout.DEFAULT_SIZE, 902, Short.MAX_VALUE)
                    .addComponent(jLabel23)
                    .addComponent(bocField, javax.swing.GroupLayout.DEFAULT_SIZE, 902, Short.MAX_VALUE)
                    .addComponent(jLabel24)
                    .addComponent(dataInputField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel22))
                .addContainerGap())
        );
        bocPanelLayout.setVerticalGroup(
            bocPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(bocPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel19)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(planoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel20)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(P2BField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel21)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radarField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel24)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dataInputField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel22)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(situacaoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel23)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bocField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(182, Short.MAX_VALUE))
        );

        tabbed2.addTab("BOC", bocPanel);

        historicoPanel.add(tabbed2, java.awt.BorderLayout.CENTER);

        tabbed1.addTab("Histórico", historicoPanel);

        getContentPane().add(tabbed1, java.awt.BorderLayout.CENTER);

        jPanel10.setBackground(new java.awt.Color(255, 255, 255));
        jPanel10.setLayout(new java.awt.BorderLayout());

        jPanel12.setBackground(new java.awt.Color(255, 255, 255));

        salvarButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/salvar.png"))); // NOI18N
        salvarButton.setText("Salvar");
        salvarButton.setEnabled(false);
        salvarButton.setPreferredSize(new java.awt.Dimension(130, 28));
        salvarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarButtonActionPerformed(evt);
            }
        });
        jPanel12.add(salvarButton);

        fecharButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/delete.png"))); // NOI18N
        fecharButton.setText("Fechar (ESC)");
        fecharButton.setPreferredSize(new java.awt.Dimension(130, 28));
        fecharButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fecharButtonActionPerformed(evt);
            }
        });
        jPanel12.add(fecharButton);

        jPanel10.add(jPanel12, java.awt.BorderLayout.LINE_END);

        jPanel13.setBackground(new java.awt.Color(255, 255, 255));

        novoPedidoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/plus_16.png"))); // NOI18N
        novoPedidoButton.setMnemonic('n');
        novoPedidoButton.setText("Novo Pedido");
        novoPedidoButton.setPreferredSize(new java.awt.Dimension(130, 28));
        novoPedidoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                novoPedidoButtonActionPerformed(evt);
            }
        });
        jPanel13.add(novoPedidoButton);

        jPanel10.add(jPanel13, java.awt.BorderLayout.LINE_START);

        getContentPane().add(jPanel10, java.awt.BorderLayout.PAGE_END);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setLayout(new java.awt.BorderLayout());

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));

        msgLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tbp/resources/venda32.png"))); // NOI18N
        msgLabel.setText("mensagem");
        jPanel4.add(msgLabel);

        empresaLabel.setFont(new java.awt.Font("Dialog", 1, 13));
        empresaLabel.setForeground(new java.awt.Color(0, 102, 255));
        jPanel4.add(empresaLabel);

        jPanel1.add(jPanel4, java.awt.BorderLayout.LINE_START);

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));
        jPanel5.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 1, 1, 1));

        jLabel4.setText("Data de Entrada:");
        jPanel5.add(jLabel4);
        jPanel5.add(dataEmissaoTextField);

        jPanel1.add(jPanel5, java.awt.BorderLayout.LINE_END);

        jPanel25.setBackground(new java.awt.Color(255, 255, 255));
        jPanel25.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 1, 1, 1));

        jLabel25.setText("Condição Padrão:");
        jPanel25.add(jLabel25);

        primeiraVendaRadio.setBackground(new java.awt.Color(255, 255, 255));
        group1.add(primeiraVendaRadio);
        primeiraVendaRadio.setForeground(new java.awt.Color(0, 51, 255));
        primeiraVendaRadio.setSelected(true);
        primeiraVendaRadio.setText("1ª VENDA");
        primeiraVendaRadio.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        primeiraVendaRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                primeiraVendaRadioActionPerformed(evt);
            }
        });
        jPanel25.add(primeiraVendaRadio);

        aditivoRadio.setBackground(new java.awt.Color(255, 255, 255));
        group1.add(aditivoRadio);
        aditivoRadio.setForeground(new java.awt.Color(0, 51, 255));
        aditivoRadio.setText("ADITIVO");
        aditivoRadio.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        aditivoRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aditivoRadioActionPerformed(evt);
            }
        });
        jPanel25.add(aditivoRadio);

        jPanel1.add(jPanel25, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_START);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void infoLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_infoLabelMouseClicked
        if (infoLabel.isEnabled()) {
            if (infoPanel.getComponentCount() > 0) {
                infoPanel.removeAll();
                infoPanel.repaint();
            }
            if (add_info) {
                infoPanel.add(new DetalhesDaEmpresaPanel(this.objetoPedido().getEmpresa()), "First");
                infoPanel.repaint();
                add_info = false;
            } else {
                add_info = true;
            }

            this.pack();
            this.setLocationRelativeTo(null);
        }
    }//GEN-LAST:event_infoLabelMouseClicked

    private void inserirButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inserirButtonActionPerformed
        this.validaItem();
}//GEN-LAST:event_inserirButtonActionPerformed

    private void fecharButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fecharButtonActionPerformed
        this.dispose();
    }//GEN-LAST:event_fecharButtonActionPerformed

    private void qtdeTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_qtdeTextFieldFocusGained
        qtdeTextField.selectAll();
    }//GEN-LAST:event_qtdeTextFieldFocusGained

    private void atualizarButonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atualizarButonActionPerformed
        alterarQuantidadeDoItem(itensDePedidoTable.getSelectedRow());
}//GEN-LAST:event_atualizarButonActionPerformed

    private void removerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removerButtonActionPerformed
        int row = itensDePedidoTable.getSelectedRow();
        if (row >= 0) {
            ItemDePedido item = model_itens_pedido.getItem(row);
            this.objetoPedido().retiraItem(item);
            refreshItensDePedido();
        }
}//GEN-LAST:event_removerButtonActionPerformed

    private void limparButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_limparButtonActionPerformed
        this.objetoPedido().limparItens();
        refreshItensDePedido();
}//GEN-LAST:event_limparButtonActionPerformed

    private void salvarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarButtonActionPerformed
        try {
            Pedido pedido = this.objetoPedido();
            if (pedido.getConsultor() == null) {
                JOptionPane.showMessageDialog(null, "O consultor do pedido deve ser selecionado.", "Falha no pedido", JOptionPane.ERROR_MESSAGE);
                return;
            } else if (pedido.getEmpresa() == null) {
                JOptionPane.showMessageDialog(null, "A empresa do pedido deve ser selecionada.", "Falha no pedido", JOptionPane.ERROR_MESSAGE);
                return;
            }
            this.capturarDadosExtras(pedido);
            ControlePedido controle_pedido = new ControlePedido();
            if (isNovoPedido()) {
                controle_pedido.registrar(pedido);
                msgLabel.setText("O pedido nº " + pedido.getId() + " foi salvo com sucesso");
                blockFinalizacao(true);
                salvarButton.setEnabled(false);
                baixarAjudaDeCusto(pedido);
            } else {
                controle_pedido.atualizar(pedido);
                msgLabel.setText("O pedido nº " + pedido.getId() + " foi atualizado com sucesso");
                empresaLabel.setText(null);
            }
            tabbed1.setSelectedIndex(0);
        } catch (PersistenciaException pex) {
            System.out.println(pex.getMessage());
        }
    }//GEN-LAST:event_salvarButtonActionPerformed

    private void novoPedidoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novoPedidoButtonActionPerformed
        setNovoPedido(true);
        setPedido(new Pedido());
        tabbed1.setSelectedIndex(0);
        tabbed2.setSelectedIndex(0);
    }//GEN-LAST:event_novoPedidoButtonActionPerformed

    private void produtoComboBoxFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_produtoComboBoxFocusLost
        this.produto_add = (Produto) produtoComboBox.getSelectedItem();
    }//GEN-LAST:event_produtoComboBoxFocusLost

    private void empresaTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_empresaTextFieldMouseClicked
        if (buscaEmpresaButton.isEnabled()) {
            buscaEmpresa();
        }
    }//GEN-LAST:event_empresaTextFieldMouseClicked

    private void consultorTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_consultorTextFieldMouseClicked
        if (buscaConsultorButton.isEnabled()) {
            buscaConsultor();
        }
    }//GEN-LAST:event_consultorTextFieldMouseClicked

    private void inserirSituacaoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inserirSituacaoButtonActionPerformed
        StatusPedido situacao = (StatusPedido) situacaoCombo.getSelectedItem();
        if (situacao == null) {
            JOptionPane.showMessageDialog(null, "A situação não foi escolhida", "Atenção", JOptionPane.WARNING_MESSAGE);
            situacaoCombo.requestFocus();
            return;
        }
        Pedido p = this.objetoPedido();
        Date data = dataEntradaExternaTextField.getDate();
        String obs = obsExternaTextArea.getText();
        if ("Provisionado".equals(situacao.getNome())) {
            Object[] opcoes = {"Confirma", "Cancela"};
            int resposta = JOptionPane.showOptionDialog(this,
                    "Escolhendo a situação de 'provisionado' o pedido nº " + p.getId() + " será finalizado,"
                    + "\nDeseja prosseguir?",
                    "Atenção", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
                    null, opcoes, opcoes[1]);
            if (resposta == 0) {
                SituacaoExterna objetoSituacaoExterna = new SituacaoExterna(situacao, data, obs, p, true);
                p.addSituacaoExternaNova(objetoSituacaoExterna);
                p.finaliza(data);
                if (p.isFinalizado()) {
                    salvarButton.doClick();
                    jLabel15.setText("O pedido foi finalizado em " + DateUtils.dataObjetoParaString(data) + ", o tempo total foi de:");
                    tempoLabel.setText(p.getTempoDecorridoEmDias() + "d");
                    salvarButton.setEnabled(false);
                    refreshSituacoesInternas();
                }
            }
        } else {
            SituacaoExterna objetoSituacaoExterna = new SituacaoExterna(situacao, data, obs, p, true);
            p.addSituacaoExternaNova(objetoSituacaoExterna);
        }
        refreshSituacoesExternas();
        mostraSituacaoExterna(null);
    }//GEN-LAST:event_inserirSituacaoButtonActionPerformed

    private void situacoesExternasTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_situacoesExternasTableMouseClicked
        if (evt.getClickCount() == 2) {
            int row = situacoesExternasTable.getSelectedRow();
            if (row >= 0) {
                SituacaoExterna s = this.objetoPedido().getSituacaoExterna(row);
                if (s != null) {
                    mostraSituacaoExterna(s);
                    podeAlterarSituacaoExterna(true);
                }
            }
        }
    }//GEN-LAST:event_situacoesExternasTableMouseClicked

    private void cancelarHistoricoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarHistoricoButtonActionPerformed
        mostraSituacaoExterna(null);
        podeAlterarSituacaoExterna(false);
    }//GEN-LAST:event_cancelarHistoricoButtonActionPerformed

    private void produtoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_produtoButtonActionPerformed
        if (produtoButton.isEnabled()) {
            ProdutosDialog dialog = new ProdutosDialog(this.menu, true);
            dialog.setSelect(true);
            dialog.setVisible(true);
            this.mostraProduto(dialog.getProduto());
            qtdeTextField.requestFocus();
        }
    }//GEN-LAST:event_produtoButtonActionPerformed

    private void portInCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_portInCheckBoxActionPerformed
        boolean state = portInCheckBox.isSelected();
        qtdePortInTextField.setEditable(state);
        qtdePortInTextField.setFocusable(state);
        jLabel8.setEnabled(state);
        qtdePortInTextField.setText("0");
        qtdePortInTextField.requestFocus(state);
    }//GEN-LAST:event_portInCheckBoxActionPerformed

    private void bocTextFieldMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_bocTextFieldMouseClicked
        if (buscaBocButton.isEnabled()) {
            buscaBoc();
        }
    }//GEN-LAST:event_bocTextFieldMouseClicked

    private void atualizarHistoricoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atualizarHistoricoButtonActionPerformed
        SituacaoExterna s = this.situacaoExterna;
        if (s != null) {
            StatusPedido situacao = (StatusPedido) situacaoCombo.getSelectedItem();
            if (situacao == null) {
                JOptionPane.showMessageDialog(null, "A situação não foi escolhida", "Atenção", JOptionPane.WARNING_MESSAGE);
                situacaoCombo.requestFocus();
                return;
            }
            Date data = dataEntradaExternaTextField.getDate();
            String obs = obsExternaTextArea.getText();
            s.setSituacao(situacao);
            s.setData(data);
            s.setObservacoes(obs);

            Pedido p = this.objetoPedido();
            p.atualizarSituacaoExterna(s);
            model_situacoes_externas.fireTableDataChanged();
            mostraSituacaoExterna(null);
            podeAlterarSituacaoExterna(false);
        }
    }//GEN-LAST:event_atualizarHistoricoButtonActionPerformed

    private void trocarDepartamentoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_trocarDepartamentoButtonActionPerformed
        Departamento dep = (Departamento) departamentoComboBox.getSelectedItem();
        if (dep == null) {
            JOptionPane.showMessageDialog(null, "O departamento não foi escolhido", "Atenção", JOptionPane.WARNING_MESSAGE);
            departamentoComboBox.requestFocus();
            return;
        }
        String obs = obsInternaTextArea.getText();
        Date data = dataEntradaInternaTextField.getDate();
        Date dataComHoras = DateUtils.addHorarioAtual(data);

        Pedido pedidoAtual = this.objetoPedido();
        SituacaoInterna novaSituacao = new SituacaoInterna(dep,
                new Timestamp(dataComHoras.getTime()), obs, pedidoAtual);
        pedidoAtual.addSituacaoInternaNova(novaSituacao);
        tempoLabel.setText(pedidoAtual.calculaTempoDecorrido());
        refreshSituacoesInternas();
    }//GEN-LAST:event_trocarDepartamentoButtonActionPerformed

    private void atualizarDepartamentoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atualizarDepartamentoButtonActionPerformed
        SituacaoInterna s = this.situacaoInterna;
        if (s != null) {
            Departamento dep = (Departamento) departamentoComboBox.getSelectedItem();
            if (dep == null) {
                JOptionPane.showMessageDialog(null, "O departamento não foi escolhido", "Atenção", JOptionPane.WARNING_MESSAGE);
                departamentoComboBox.requestFocus();
                return;
            }
            String obs = obsInternaTextArea.getText();
            Date data = dataEntradaInternaTextField.getDate();
            Date dataComHoras = DateUtils.addHorarioAtual(data);
            s.setDepartamento(dep);
            s.setDataDeEntrada(new Timestamp(dataComHoras.getTime()));
            s.setObservacoes(obs);

            Pedido p = this.objetoPedido();
            p.atualizarSituacaoInterna(s);
            model_situacoes_internas.fireTableDataChanged();
            mostraSituacaoInterna(null);
            podeAlterarSituacaoInterna(false);
        }
    }//GEN-LAST:event_atualizarDepartamentoButtonActionPerformed

    private void cancelarDepartamentoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarDepartamentoButtonActionPerformed
        mostraSituacaoInterna(null);
        podeAlterarSituacaoInterna(false);
    }//GEN-LAST:event_cancelarDepartamentoButtonActionPerformed

    private void situacoesInternasTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_situacoesInternasTableMouseClicked
        if (evt.getClickCount() == 2) {
            int row = situacoesInternasTable.getSelectedRow();
            if (row >= 0) {
                SituacaoInterna s = this.objetoPedido().getSituacaoInterna(row);
                if (s != null) {
                    mostraSituacaoInterna(s);
                    podeAlterarSituacaoInterna(true);
                }
            }
        }
    }//GEN-LAST:event_situacoesInternasTableMouseClicked

    private void tabbed2StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tabbed2StateChanged
        this.atualizarBocInfo();
    }//GEN-LAST:event_tabbed2StateChanged

    private void tabbed1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tabbed1StateChanged
        int tab = tabbed1.getSelectedIndex();
        if (tab == 1) {
            this.atualizarBocInfo();
        }
    }//GEN-LAST:event_tabbed1StateChanged

    private void excluirSituacaoInternaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_excluirSituacaoInternaButtonActionPerformed
        int row = situacoesInternasTable.getSelectedRow();
        if(row >= 0) {
            SituacaoInterna situacao = model_situacoes_internas.getSituacaoInterna(row);
            if(situacao != null) {
                model_situacoes_internas.removeSituacaoInterna(situacao);
            }
        }
    }//GEN-LAST:event_excluirSituacaoInternaButtonActionPerformed

    private void excluirSituacaoExternaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_excluirSituacaoExternaButtonActionPerformed
        int row = situacoesExternasTable.getSelectedRow();
        if(row >= 0) {
            SituacaoExterna situacao = model_situacoes_externas.getSituacaoExterna(row);
            if(situacao != null) {
                model_situacoes_externas.removeSituacaoExterna(situacao);
            }
        }
    }//GEN-LAST:event_excluirSituacaoExternaButtonActionPerformed

    private void primeiraVendaRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_primeiraVendaRadioActionPerformed
        selectCondicaoPadrao();
    }//GEN-LAST:event_primeiraVendaRadioActionPerformed

    private void aditivoRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aditivoRadioActionPerformed
        selectCondicaoPadrao();
    }//GEN-LAST:event_aditivoRadioActionPerformed
    // <editor-fold defaultstate="collapsed" desc="Declaration of class members">
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField P2BField;
    private javax.swing.JRadioButton aditivoRadio;
    private javax.swing.JButton atualizarButon;
    private javax.swing.JButton atualizarDepartamentoButton;
    private javax.swing.JButton atualizarHistoricoButton;
    private javax.swing.JPanel basicoPanel;
    private javax.swing.JTextField bocField;
    private javax.swing.JPanel bocPanel;
    private javax.swing.JTextField bocTextField;
    private javax.swing.JButton cancelarDepartamentoButton;
    private javax.swing.JButton cancelarHistoricoButton;
    private javax.swing.JComboBox condicaoComboBox;
    private javax.swing.JTextField consultorTextField;
    private org.jdesktop.swingx.JXDatePicker dataEmissaoTextField;
    private org.jdesktop.swingx.JXDatePicker dataEntradaExternaTextField;
    private org.jdesktop.swingx.JXDatePicker dataEntradaInternaTextField;
    private org.jdesktop.swingx.JXDatePicker dataInputField;
    private javax.swing.JComboBox departamentoComboBox;
    private javax.swing.JLabel empresaLabel;
    private javax.swing.JTextField empresaTextField;
    private javax.swing.JButton excluirSituacaoExternaButton;
    private javax.swing.JButton excluirSituacaoInternaButton;
    private javax.swing.JPanel externoPanel;
    private javax.swing.JButton fecharButton;
    private javax.swing.JLabel finalizadoLabel;
    private javax.swing.ButtonGroup group1;
    private javax.swing.JPanel historicoPanel;
    private javax.swing.JTextField idBocTexField;
    private javax.swing.JTextField idConsultorTexField;
    private javax.swing.JTextField idEmpresaTexField;
    private javax.swing.JTextField idSupervisorTexField;
    private javax.swing.JLabel infoLabel;
    private javax.swing.JPanel infoPanel;
    private javax.swing.JButton inserirButton;
    private javax.swing.JButton inserirSituacaoButton;
    private javax.swing.JPanel internoPanel;
    private javax.swing.JTable itensDePedidoTable;
    private javax.swing.JLabel itensLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel16;
    private javax.swing.JPanel jPanel17;
    private javax.swing.JPanel jPanel18;
    private javax.swing.JPanel jPanel19;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel20;
    private javax.swing.JPanel jPanel21;
    private javax.swing.JPanel jPanel22;
    private javax.swing.JPanel jPanel23;
    private javax.swing.JPanel jPanel24;
    private javax.swing.JPanel jPanel25;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel43;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton limparButton;
    private javax.swing.JLabel msgLabel;
    private javax.swing.JButton novoPedidoButton;
    private javax.swing.JTextArea obsExternaTextArea;
    private javax.swing.JTextArea obsInternaTextArea;
    private javax.swing.JTextField planoField;
    private javax.swing.JCheckBox portInCheckBox;
    private javax.swing.JRadioButton primeiraVendaRadio;
    private javax.swing.JButton produtoButton;
    private javax.swing.JComboBox produtoComboBox;
    private javax.swing.JLabel produtosLabel;
    private javax.swing.JTextField qtdePortInTextField;
    private javax.swing.JTextField qtdeTextField;
    private javax.swing.JTextField radarField;
    private javax.swing.JButton removerButton;
    private javax.swing.JButton salvarButton;
    private javax.swing.JScrollPane scrollpane;
    private javax.swing.JComboBox situacaoCombo;
    private javax.swing.JTextField situacaoField;
    private javax.swing.JTable situacoesExternasTable;
    private javax.swing.JTable situacoesInternasTable;
    private javax.swing.JTextField supervisorTextField;
    private javax.swing.JTabbedPane tabbed1;
    private javax.swing.JTabbedPane tabbed2;
    private javax.swing.JLabel tempoLabel;
    private javax.swing.JButton trocarDepartamentoButton;
    // End of variables declaration//GEN-END:variables
    // </editor-fold>

    public void setPedido(Pedido p) {
        this.pedido = p;
        dataEmissaoTextField.setDate(new Date(p.getData().getTime()));

        idConsultorTexField.setText(p.getConsultor() != null ? p.getConsultor().getId() + "" : null);
        consultorTextField.setText(p.getConsultor() != null ? p.getConsultor().getNome() : null);

        idEmpresaTexField.setText(p.getEmpresa() != null ? p.getEmpresa().getId() + "" : null);
        empresaTextField.setText(p.getEmpresa() != null ? p.getEmpresa().getRazaoSocial() + "      [" + p.getEmpresa().getCnpj() + "]" : null);

        idSupervisorTexField.setText(p.getSupervisor() != null ? p.getSupervisor().getId() + "" : null);
        supervisorTextField.setText(p.getSupervisor() != null ? p.getSupervisor().getNome() + "" : null);

        idBocTexField.setText(p.getBoc() != null ? p.getBoc().getId() + "" : null);
        bocTextField.setText(p.getBoc() != null ? p.getBoc().getNome() + "" : null);

        model_itens_pedido = new ItensDePedidoTableModel(p);
        itensDePedidoTable.setModel(model_itens_pedido);

        model_situacoes_externas = new SituacoesExternasTableModel(p);
        situacoesExternasTable.setModel(model_situacoes_externas);

        model_situacoes_internas = new SituacoesInternasTableModel(p);
        situacoesInternasTable.setModel(model_situacoes_internas);

        if (pedido.isFinalizado()) {
            jLabel15.setText("O pedido foi finalizado em " + DateUtils.dataObjetoParaString(p.getDataDeFinalizacao()) + ", o tempo total foi de:");
            tempoLabel.setText(p.calculaTempoDecorrido());
        } else {
            jLabel15.setText("O pedido está em aberto, o tempo até o momento é de:");
            tempoLabel.setText(p.calculaTempoDecorrido());
        }
        refreshItensDePedido();
        refreshSituacoesInternas();
        refreshSituacoesExternas();

        planoField.setText(p.getBocInfo().getPlano());
        P2BField.setText(p.getBocInfo().getP2B());
        radarField.setText(p.getBocInfo().getRadar());
        dataInputField.setDate(p.getBocInfo().getDataInput());
    }

    public boolean isNovoPedido() {
        return novoPedido;
    }

    public void setNovoPedido(boolean novoPedido) {
        this.novoPedido = novoPedido;
        if (isNovoPedido()) {
            msgLabel.setText("Forneça os dados para o novo pedido");
            empresaLabel.setText(null);
            buscaConsultorButton.setEnabled(true);
            blockFinalizacao(true);
            updateEmpresaButton.setEnabled(false);
        } else {
            msgLabel.setText("Pedido nº " + this.objetoPedido().getId() + "  - ");
            empresaLabel.setText(this.objetoPedido().getEmpresa().getNomeFantasia());
            if (this.objetoPedido().isFinalizado()) {
                salvarButton.setEnabled(false);
                finalizadoLabel.setText("O pedido foi finalizado em "
                        + DateUtils.dataObjetoParaString(this.objetoPedido().getDataDeFinalizacao()) + ", o tempo total foi de: "
                        + this.objetoPedido().getTempoDecorridoEmDias() + "d");
            } else {
                salvarButton.setEnabled(true);
            }
            buscaConsultorButton.setEnabled(false);
            buscaEmpresaButton.setEnabled(false);
            //buscaBocButton.setEnabled(false);
            updateEmpresaButton.setEnabled(true);
        }
        mostraProduto(null);
    }

    private void validaItem() {
        if (produto_add != null) {
            if (!produto_add.isAtivo()) {
                JOptionPane.showMessageDialog(null, "O produto " + produto_add.getNome() + " está desativado.",
                        "Atenção", JOptionPane.WARNING_MESSAGE);
                return;
            }
            ItemDePedido item =
                    new ItemDePedido(produto_add, 0);
            /*
            boolean contem = this.objetoPedido().contemItem(item);
            if (contem) {
            JOptionPane.showMessageDialog(null, "O item " + item.getProduto().getNome()
            + " já consta na lista do pedido\ne não pode ser inserido novamente.",
            "Aviso", JOptionPane.WARNING_MESSAGE);
            mostraProduto(null);
            return;
            }
             */
            try {
                int qtde = Integer.parseInt(qtdeTextField.getText());
                if (qtde < 1) {
                    throw new NumberFormatException();
                }
            } catch (NumberFormatException nfe) {
                qtdeTextField.setText("0");
                qtdeTextField.requestFocus();
                qtdeTextField.selectAll();
                return;
            }

            if (portInCheckBox.isSelected()) {
                try {
                    int qtde = Integer.parseInt(qtdePortInTextField.getText());
                    if (qtde < 1) {
                        throw new NumberFormatException();
                    }
                } catch (NumberFormatException nfe) {
                    qtdePortInTextField.setText("0");
                    qtdePortInTextField.requestFocus();
                    qtdePortInTextField.selectAll();
                    return;
                }
            }
            item.setQuantidade(Integer.parseInt(qtdeTextField.getText()));
            item.setCondicao((CondicaoDaLinha) condicaoComboBox.getSelectedItem());
            item.setQtdeAtivada(Integer.parseInt(qtdeTextField.getText()));
            if (portInCheckBox.isSelected()) {
                item.setPortIn(true);
                item.setQtePortIn(Integer.parseInt(qtdePortInTextField.getText()));
            }
            this.addItem(item);
        } else {
            produtoComboBox.requestFocus();
        }
    }

    private Pedido objetoPedido() {
        return this.pedido;
    }

    private void refreshItensDePedido() {
        model_itens_pedido.fireTableDataChanged();
        JTableUtils.fitAllColumns(itensDePedidoTable);
        Pedido p = this.objetoPedido();
        produtosLabel.setText("Qtde de produtos: " + p.qtde_de_produtos());
        itensLabel.setText("Qtde de itens: " + p.qtde_de_itens());

        if (isNovoPedido()) {
            qtdeTextField.setText("0");
            salvarButton.setEnabled(p.qtde_de_produtos() > 0);
        }
    }

    private void refreshSituacoesExternas() {
        model_situacoes_externas.fireTableDataChanged();
        JTableUtils.fitAllColumnsWithoutRenderer(situacoesExternasTable);
    }

    private void refreshSituacoesInternas() {
        model_situacoes_internas.fireTableDataChanged();
        JTableUtils.fitAllColumnsWithoutRenderer(situacoesInternasTable);
    }

    public Pedido getPedido() {
        pedido.setData(dataEmissaoTextField.getDate());
        return pedido;
    }

    private void setEmpresa(Empresa e) {
        if (e != null) {
            this.objetoPedido().setEmpresa(e);
            idEmpresaTexField.setText(e != null ? e.getId() + "" : null);
            empresaTextField.setText(e != null ? e.getRazaoSocial() + "      [" + e.getCnpj() + "]" : null);
            updateEmpresaButton.setEnabled(true);
        }
        blockFinalizacao(this.objetoPedido().getEmpresa() == null);
    }

    private void setConsultor(Consultor c) {
        if (c != null) {
            this.objetoPedido().setConsultor(c);
            idConsultorTexField.setText(c != null ? c.getId() + "" : null);
            consultorTextField.setText(c != null ? c.getNome() : null);
        }
        setSupervisor(c.getSupervisor());
    }

    private void setSupervisor(Supervisor s) {
        this.objetoPedido().setSupervisor(s);
        idSupervisorTexField.setText(s != null ? s.getId() + "" : null);
        supervisorTextField.setText(s != null ? s.getNome() : null);
    }

    private void setBoc(Boc b) {
        if (b != null) {
            this.objetoPedido().setBoc(b);
            idBocTexField.setText(b != null ? b.getId() + "" : null);
            bocTextField.setText(b != null ? b.getNome() : null);
        }
    }

    private void mostraProduto(Produto p) {
        this.produto_add = p;
        if (p != null) {
            produtoComboBox.setSelectedItem(p);
            qtdeTextField.setText("0");
        } else {
            produtoComboBox.setSelectedItem(null);
            qtdeTextField.setText("0");
            produtoComboBox.requestFocus();
            //condicaoComboBox.setSelectedIndex(0);
            portInCheckBox.setSelected(false);
            jLabel8.setEnabled(false);
            qtdePortInTextField.setEditable(false);
            qtdePortInTextField.setFocusable(false);
            qtdePortInTextField.setText("0");
        }
    }

    private void addItem(ItemDePedido item) {
        Pedido p = this.objetoPedido();
        p.addItem(item);
        refreshItensDePedido();
        mostraProduto(null);
        selectCondicaoPadrao();
    }

    @Override
    protected JRootPane createRootPane() {
        ActionListener closeListener = new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                fecharButtonActionPerformed(e);
            }
        };
        KeyStroke stroke =
                KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
        JRootPane myRootPane = new JRootPane();
        myRootPane.registerKeyboardAction(
                closeListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);

        return myRootPane;
    }

    private void alterarQuantidadeDoItem(int row) {
        if (row >= 0) {
            ItemDePedido item = model_itens_pedido.getItem(row);
            String str = (String) JOptionPane.showInputDialog(null,
                    "Nova Quantidade: ", "Alterar Quantidade '" + item.getProduto().getNome() + "'", JOptionPane.WARNING_MESSAGE,
                    null, null, item.getQtde());
            try {
                int qtde = Integer.parseInt(str);
                this.objetoPedido().alterarQuantidadeDoItem(item, qtde);
                refreshItensDePedido();
            } catch (NumberFormatException nfe) {
                return;
            }
        }
    }

    private void blockFinalizacao(boolean b) {
        b = !b;
        produtoComboBox.setEnabled(b);
        produtoComboBox.setFocusable(b);
        infoLabel.setEnabled(b);
        produtoButton.setEnabled(b);
        qtdeTextField.setEditable(b);
        condicaoComboBox.setEnabled(b);
        portInCheckBox.setEnabled(b);
        inserirButton.setEnabled(b);
        produtosLabel.setEnabled(b);
        itensLabel.setEnabled(b);
        itensDePedidoTable.setEnabled(b);
        atualizarButon.setEnabled(b);
        removerButton.setEnabled(b);
        limparButton.setEnabled(b);
    }

    public MenuPrincipal getMenu() {
        return menu;
    }

    private void carregaComboProdutos() {
        try {
            ControleProduto controle = new ControleProduto();
            DefaultComboBoxModel combo_model = new DefaultComboBoxModel(controle.pesquisar().toArray());
            produtoComboBox.setModel(combo_model);
        } catch (PersistenciaException pex) {
            System.out.println(pex.getMessage());
        }
    }

    private void carregaComboStatus() {
        try {
            ControlePedido controle = new ControlePedido();
            DefaultComboBoxModel combo_model = new DefaultComboBoxModel(controle.pesquisarStatusDisponiveis().toArray());
            situacaoCombo.setModel(combo_model);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }

    private JButton buscaConsultorButton() {
        consultorTextField.setLayout(new BorderLayout());
        buscaConsultorButton = new JButton(ImageUtils.createIcon("search16.png"));
        buscaConsultorButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
        buscaConsultorButton.setToolTipText("Clique para buscar um consultor");

        buscaConsultorButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                buscaConsultor();
            }
        });
        return buscaConsultorButton;
    }

    private JButton getBuscaEmpresaButton() {
        empresaTextField.setLayout(new BorderLayout());
        buscaEmpresaButton = new JButton(ImageUtils.createIcon("search16.png"));
        buscaEmpresaButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
        buscaEmpresaButton.setToolTipText("Clique para buscar uma empresa");

        buscaEmpresaButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                buscaEmpresa();
            }
        });
        return buscaEmpresaButton;
    }

    private JButton getUpdateEmpresaButton() {
        updateEmpresaButton = new JButton(ImageUtils.createIcon("refresh16x16.png"));
        updateEmpresaButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
        updateEmpresaButton.setToolTipText("Clique para editar a empresa");

        updateEmpresaButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                updateEmpresa();
            }
        });
        return updateEmpresaButton;
    }

    private JButton buscaBocButton() {
        bocTextField.setLayout(new BorderLayout());
        buscaBocButton = new JButton(ImageUtils.createIcon("search16.png"));
        buscaBocButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
        buscaBocButton.setToolTipText("Clique para buscar um boc");

        buscaBocButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                buscaBoc();
            }
        });
        return buscaBocButton;
    }

    private void buscaConsultor() {
        ConsultoresDialog dialog = new ConsultoresDialog(menu, true);
        dialog.setSelect(true);
        dialog.setVisible(true);
        this.setConsultor(dialog.getConsultor());
    }

    private void buscaBoc() {
        BocsDialog dialog = new BocsDialog(menu, true);
        dialog.setSelect(true);
        dialog.setVisible(true);
        this.setBoc(dialog.getBoc());
    }

    private void buscaEmpresa() {
        EmpresasPaginadaDialog dialog = new EmpresasPaginadaDialog(menu, true);
        dialog.setSelect(true);
        dialog.setVisible(true);
        this.setEmpresa(dialog.getEmpresa());
    }

    private void updateEmpresa() {
        try {
            if (objetoPedido().getEmpresa() == null) {
                return;
            }
            ControleEmpresa controle = new ControleEmpresa();
            Empresa e = controle.pesquisarPorId(objetoPedido().getEmpresa().getId());
            if (e != null) {
                EmpresaDialog dialog = new EmpresaDialog(menu, "TBP - Empresa", true);
                dialog.setEmpresa(e);
                dialog.setNovaEmpresa(false);
                dialog.setVisible(true);
                setEmpresa(dialog.objetoEmpresa());
            }
        } catch (PersistenciaException pex) {
            System.out.println(pex.getMessage());
        }
    }

    private void mostraSituacaoExterna(SituacaoExterna s) {
        this.situacaoExterna = s;
        if (s != null) {
            situacaoCombo.setSelectedItem(s.getSituacao());
            dataEntradaExternaTextField.setDate(s.getData());
            obsExternaTextArea.setText(s.getObservacoes());
        } else {
            situacaoCombo.setSelectedIndex(-1);
            dataEntradaExternaTextField.setDate(new Date());
            obsExternaTextArea.setText(null);
        }
        obsExternaTextArea.setCaretPosition(0);
        situacaoCombo.requestFocus();
    }

    private void mostraSituacaoInterna(SituacaoInterna s) {
        this.situacaoInterna = s;
        if (s != null) {
            departamentoComboBox.setSelectedItem(s.getDepartamento());
            dataEntradaInternaTextField.setDate(s.getDataDeEntrada());
            obsInternaTextArea.setText(s.getObservacoes());
        } else {
            departamentoComboBox.setSelectedIndex(-1);
            dataEntradaInternaTextField.setDate(new Date());
            obsInternaTextArea.setText(null);
        }
        obsInternaTextArea.setCaretPosition(0);
        departamentoComboBox.requestFocus();
    }

    private void podeAlterarSituacaoExterna(boolean b) {
        atualizarHistoricoButton.setEnabled(b);
        cancelarHistoricoButton.setEnabled(b);
        inserirSituacaoButton.setEnabled(!b);
    }

    private void podeAlterarSituacaoInterna(boolean b) {
        atualizarDepartamentoButton.setEnabled(b);
        cancelarDepartamentoButton.setEnabled(b);
        trocarDepartamentoButton.setEnabled(!b);
    }

    private void posInit() {
        carregaComboProdutos();
        carregaComboStatus();
        consultorTextField.add(buscaConsultorButton(), "After");
        JPanel panel = new JPanel(new BorderLayout());
        panel.add(getBuscaEmpresaButton(), "After");
        panel.add(getUpdateEmpresaButton(), "Before");
        empresaTextField.add(panel, "After");
        bocTextField.add(buscaBocButton(), "After");
        Atributo.reagirEnter(inserirButton);
        dataEntradaInternaTextField.setDate(new Date());
        dataEntradaExternaTextField.setDate(new Date());
        buscaConsultorButton.requestFocus();
        setLocationRelativeTo(null);
    }

    private void capturarDadosExtras(Pedido p) {
        p.setData(dataEmissaoTextField.getDate());
        p.getBocInfo().setPlano(planoField.getText());
        p.getBocInfo().setP2B(P2BField.getText());
        p.getBocInfo().setRadar(radarField.getText());
        p.getBocInfo().setDataInput(dataInputField.getDate());
    }

    private void atualizarBocInfo() {
        int tab = tabbed2.getSelectedIndex();
        if (tab == 2) {
            StatusPedido s = this.objetoPedido().getSituacaoExternaAtual();
            situacaoField.setText(s != null ? s.getNome() : null);
            Boc boc = this.objetoPedido().getBoc();
            bocField.setText(boc != null ? boc.getNome() : null);
            planoField.requestFocus();
        }
    }

    private void baixarAjudaDeCusto(Pedido pedido) {
        try {
            ControleAjudaCusto controle = new ControleAjudaCusto();
            controle.baixarAjudaDeCusto(pedido);
        } catch (PersistenciaException pex) {
            System.out.println(pex.getMessage());
        }
    }

    private void selectCondicaoPadrao() {
        if(primeiraVendaRadio.isSelected()) {
            condicaoComboBox.setSelectedItem(CondicaoDaLinha.PRIMEIRA_VENDA);
        } else if(aditivoRadio.isSelected()) {
            condicaoComboBox.setSelectedItem(CondicaoDaLinha.ADITIVO);
        }
    }
}
